package com.ykw.parking.controller;

import com.ykw.parking.Utils.RandomId;
import com.ykw.parking.service.MailServiceImpl;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class SendMailController {
    @Autowired
    MailServiceImpl mailService;
    @RequestMapping(value = "/email",method = RequestMethod.POST)
    @ResponseBody
    public String test(String email,HttpSession session){
        String  num= RandomId.getRandomNumberByNum(5);//获取5位验证码
        session.setAttribute("Expiration",System.currentTimeMillis());
        session.setAttribute("Verification",num);
//        String subject="拴马桩注册";
//        String context="您的注册验证码为:"+num+"五分钟失效";
//        mailService.sendSimpleMail(to,subject,context);
        try {
            mailService.sendInlineResourceMail(email,num);
            return "1";
        } catch (MessagingException e) {
            return "0";
        }
    }
}
